<div [@routerTransition]>

    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("Roles")}}</span>
                </h3>
                <span class="m-section__sub">
                    {{l("RolesHeaderInfo")}}
                </span>
            </div>
            <div class="col-xs-6 text-right">
                <button (click)="createRole()" *ngIf="isGranted('Pages.Administration.Roles.Create')" class="btn btn-primary"><i class="fa fa-plus"></i> {{l("CreateNewRole")}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="m-form m-form--label-align-right">
                    <div class="row m--margin-bottom-10">
                        <div class="col-xl-6">
                            <div class="form-group">
                                <permission-combo [(selectedPermission)]="selectedPermission"></permission-combo>
                            </div>
                        </div>
                        <div class="col-xl-6 text-right">
                            <button name="RefreshButton" class="btn btn-metal" (click)="getRoles()"><i class="la la-refresh"></i> {{l('Refresh')}}</button>
                        </div>
                    </div>
                </div>
                <div class="row align-items-center">
                    <!--<Primeng-TurboTable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable
                                 (onLazyLoad)="getRoles()"
                                 [value]="primengTableHelper.records"
                                 rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                 [paginator]="false"
                                 [lazy]="true"
                                 [responsive]="primengTableHelper.isResponsive">

                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width: 130px" [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">{{l('Actions')}}</th>
                                    <th>{{l('RoleName')}}</th>
                                    <th>{{l('CreationTime')}}</th>
                                </tr>
                            </ng-template>

                            <ng-template pTemplate="body" let-record="$implicit">
                                <tr>
                                    <td [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">
                                        <div class="btn-group dropdown">
                                            <button class="dropdown-toggle btn btn-primary btn-sm dropdown-toggle"
                                                    data-toggle="dropdown"
                                                    aria-haspopup="true"
                                                    aria-expanded="false">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a *ngIf="permission.isGranted('Pages.Administration.Roles.Edit')"
                                                       (click)="createOrEditRoleModal.show(record.id)">{{l('Edit')}}</a>
                                                </li>
                                                <li>
                                                    <a *ngIf="!record.isStatic && permission.isGranted('Pages.Administration.Roles.Delete')"
                                                       (click)="deleteRole(record)">{{l('Delete')}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('RoleName')}}</span>
                                        <span>
                                            {{record.displayName}}
                                            <span *ngIf="record.isStatic"
                                                  class="m-badge m-badge--brand m-badge--wide"
                                                  data-toggle="tooltip"
                                                  title="{{l('StaticRole_Tooltip')}}"
                                                  data-placement="top">
                                                {{l('Static')}}
                                            </span>
                                            <span *ngIf="record.isDefault"
                                                  class="m-badge m-badge--metal m-badge--wide"
                                                  data-toggle="tooltip"
                                                  title="{{l('DefaultRole_Description')}}"
                                                  data-placement="top">
                                                {{l('Default')}}
                                            </span>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{l('CreationTime')}}</span>
                                        {{record.creationTime | momentFormat:'L'}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>
                        <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                            {{l('NoData')}}
                        </div>
                        <div class="ui-table-footer">
                            {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->
                </div>
            </div>
        </div>
    </div>

    <createOrEditRoleModal #createOrEditRoleModal (modalSave)="getRoles()"></createOrEditRoleModal>
</div>
